#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;

stack<char> ops;
stack<int> nums;
unordered_map<char, int> priority{{'+', 0}, {'-', 0}, {'*', 1}, {'/', 1}};
int cal(char op, int first, int second) {
    if (op == '+')
        return first + second;
    else if (op == '-')
        return first - second;
    else if (op == '*')
        return first * second;
    else if (op == '/')
        return first / second;
    cout << "cal bug" << endl;
    return 0;
}

int solve(string s) {
    int n = s.size();
    int num = 0;
    for (int i = 0; i < n; i++) {
        cout << i << endl;
        if (s[i] >= '0' && s[i] <= '9') {
            num *= 10;
            num += s[i] - '0';
            if (i == n - 1 || s[i + 1] < '0' || s[i + 1] > '9') {
                nums.push(num);
                num = 0;
            }
        } else {
            if (s[i] == '(') {
                ops.push('(');
            } else if (s[i] == ')') {
                while (ops.top() != '(') {
                    int second = nums.top();
                    nums.pop();
                    int first = nums.top();
                    nums.pop();
                    char op = ops.top();
                    ops.pop();
                    nums.push(cal(op, first, second));
                }
                ops.pop();
            } else {
                while (!ops.empty() && ops.top() != '(' && priority[s[i]] <= priority[ops.top()]) {
                    int second = nums.top();
                    nums.pop();
                    int first = nums.top();
                    nums.pop();
                    char op = ops.top();
                    ops.pop();
                    nums.push(cal(op, first, second));
                }
                ops.push(s[i]);
            }
        }
    }
    while (!ops.empty()) {
        char op = ops.top();
        ops.pop();
        int second = nums.top();
        nums.pop();
        int first = nums.top();
        nums.pop();
        nums.push(cal(op, first, second));
    }
    return nums.top();
}